import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children:[
      {
        path: '/home/searchpopup',
        component: () => import(/* webpackChunkName: "searchpopup" */ '../views/SearchPopup.vue')
      }
    ],
    meta:{
      tabbarActiveNum:0
    }
  },
  {
    path: '/topic',
    component: () => import(/* webpackChunkName: "topic" */ '../views/Topic.vue'),
    meta:{
      tabbarActiveNum:1
    }
  },
  {
    path: '/category',
    component: () => import(/* webpackChunkName: "topic" */ '../views/Category.vue'),
    meta:{
      tabbarActiveNum:2
    }
  },
  {
    path: '/cart',
    component: () => import(/* webpackChunkName: "topic" */ '../views/Cart.vue'),
    meta:{
      tabbarActiveNum:3
    }
  },
  {
    path: '/user',
    component: () => import(/* webpackChunkName: "topic" */ '../views/User.vue'),
    meta:{
      tabbarActiveNum:4
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由守卫/ 路由拦截
router.beforeEach((to,from,next)=>{

  // if(to.path=='/cart'){

  //   let token = localStorage.getItem('token')
  //   if(token){
  //     next()
  //   }else{
  //     Vue.prototype.$toast('请先登录！')
  //     setTimeout(() => {
  //        next('/user')
  //     },800);
     
  //   }

  //   return
  // }

  next()
})


export default router
